package com.example.smartcity_poverty.ui.AllService.TakeOutTr.adapter

import android.content.Intent
import androidx.annotation.LayoutRes
import com.example.smartcity_poverty.App
import com.example.smartcity_poverty.App.Companion.url
import com.example.smartcity_poverty.Base.BaseRecyclerAdapter
import com.example.smartcity_poverty.R
import com.example.smartcity_poverty.logic.model.TakeOutModel.ToShopModel
import com.example.smartcity_poverty.logic.util.Util.glide
import com.example.smartcity_poverty.ui.AllService.TakeOutTr.activity.ShopMessageViewActivity
import kotlinx.android.synthetic.main.re_take_shop.*

/**
 *  ANDROID STUDIO -VERSION 4.0
 *  email: 2506789532@qq.com
 *  CodeAuthor： Ikun
 *
 *  explain: 外卖店家列表适配器
 **/
class ToShopAdapter(
    val list: MutableList<ToShopModel.Row>,
    @LayoutRes
    val layoutId: Int
) : BaseRecyclerAdapter<ToShopModel.Row>(list, R.layout.re_take_shop) {
    override fun setData(
        view: BaseViewHolder.ViewFind,
        data: ToShopModel.Row,
        position: Int,
        holder: BaseViewHolder
    ) {
        // 设置动画
        holder.itemView.animation = App.getAnimationBottomAndTop()
        // 填充数据
        list[position].apply {
            // 店家图片
            glide(url + this.imgUrl, holder.viewFind.toShopImg)
            // 店家名称
            view.toShopTitle.text = this.name
            // 评分
            view.toShopScore.text = "${this.score}分"
            // 月销量
            view.toShopSaleQuantity.text = "月销量 ${this.saleQuantity}"
            // 人均 ￥
            view.toShopAvgCost.text = "人均 ￥${this.avgCost}"
            // 配送时间
            view.toShopDeliveryTime.text = "${this.deliveryTime}分钟"
            // 到店时间
            view.toShopDistance.text = "到店 ${this.distance}米"
            // 店家简介
            view.toShopIntroduction.text = this.introduction
        }.apply {
            val id = this.id.toString()
            // 点击跳转到店家详情页
            holder.itemView.setOnClickListener {
                holder.itemView.context.startActivity(
                    Intent(
                        holder.itemView.context, ShopMessageViewActivity::class.java
                    ).apply {
                        putExtra("id", id)
                    }
                )
            }
        }
    }
}